﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RedemptoristRetreatCenter.HelperUtility
{
    public class ConversionUtility
    {
        public int booleanToInt(bool booleanValue)
        {
            if (booleanValue)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        public int stringToInt(string stringValue)
        {
            int intValue;
            bool isNbr = int.TryParse(stringValue, out intValue);
            if (!isNbr)
            {
                Console.WriteLine(String.Format("Could not convert {0} to integer....defaulting to 0", stringValue));
                intValue = 0;
            }

            return intValue;
        }

        public double stringToDouble(string stringValue)
        {
            double doubleValue;
            bool isNbr = double.TryParse(stringValue, out doubleValue);
            if (!isNbr)
            {
                Console.WriteLine(String.Format("Could not convert {0} to double....defaulting to 0", stringValue));
                doubleValue = 0;
            }

            return doubleValue;
        }


        public DateTime stringToDateTime(string stringValue)
        {
            DateTime dateTimeValue;

            bool isDateTime = DateTime.TryParse(stringValue, out dateTimeValue);

            if (!isDateTime)
            {
                Console.WriteLine(String.Format("Could not convert {0} to DateTime....defaulting to current time", stringValue));
                dateTimeValue = DateTime.Now;
            }

            return dateTimeValue;
        }

        public string boolToYesNo(bool booleanValue)
        {
            if (booleanValue)
            {
                return "Yes";
            }
            else
            {
                return "No";
            }
        }
    }
}